package vsm.vsm_server.service.impl;

import org.springframework.stereotype.Service;
import vsm.vsm_server.mapper.TagMapper;
import vsm.vsm_server.pojo.Tag;
import vsm.vsm_server.service.TagService;

import java.math.BigInteger;

@Service
public class TagServiceImpl implements TagService {

    private TagMapper tagMapper;
    public TagServiceImpl(TagMapper tagMapper){this.tagMapper=tagMapper;}
    @Override
    public BigInteger saveTag(String content) {
        //1.查询存在
        //若存在直接返回若不存在则保存再返回
       BigInteger tagId =  tagMapper.existTag(content);
       if(tagId ==null){
           Tag tag = new Tag();
           tag.setContent(content);
           tagMapper.saveTag(tag);
           tagId = tag.getTagId();
       }
        return tagId;
    }

    @Override
    public String getTagContent(BigInteger tagId) {
        return tagMapper.getTagContent(tagId);
    }


}
